package day1;

public class TextLambda {
    public static void main(String[] args) {
        testA();
        testB();
        testC();
        testD();
    }

    public static void testD() {
        //1、接口的匿名内部对象
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return a > b ? a : b;
            }
        };

        //2、调用接口的Lambda表达式
        D d2 = (a, b) -> a > b ? a : b;
        int max1 = d2.max(5, 4);
        System.out.println(max1);

        //3、方法引用Lambda表达式
        D d3 = Math::max;
        int max = d3.max(5, 4);
        System.out.println(max);
    }


    public static void testC() {
        //1、C接口的匿名内部对象
        C c1 = new C() {
            @Override
            public String show(String name) {
                return  name;
            }
        };
        String name3 = c1.show("tongtongtongsahur");
        System.out.println(name3);

        //2、调用C接口的Lambda表达式
        C c2 = name->  name;
        String name2 = c2.show("talaerotalala");
        System.out.println(name2);

        //3、方法引用Lambda表达式
        C c3 = TextLambda::show4;
        String name = c3.show("bombardiro crocodilo");
        System.out.println(name);
    }
    public static String show4(String name) {
        return   name;
    }


    private static void testB() {
        //1、B接口的匿名内部对象
        B b1 = new B() {
            @Override
            public void show(String name) {
                System.out.println("Name: " + name);
            }
        };
        b1.show("zhangsan");

        //2、匿名内部类对象Lambda表达式
        B b2 = name-> System.out.println(name);
        b2.show("wangwu");

        //3、方法引用Lambda表达式
        B b3 = System.out::println;
        b3.show("lisi");
        }

    private static void testA() {
        //1、
        A a1 = new A() {
            @Override
            public void show(String name, int age) {
                System.out.println("Name: " + name + ", Age: " + age);
            }
        };
        a1.show("Tom", 25);

        //2.匿名内部类对象Lambda表达式
        A a2 = (name, age) -> System.out.println("Name: " + name + ", Age: " + age);
        a2.show("Jerry", 30);

        //3、方法引用Lambda表达式
        A a3 = TextLambda::show2;
        a3.show("zhangsan", 85);
    }
    private static void show2(String name, int age) {
        System.out.println(name + age);
    }
}
